#include "rectangle.h"

Rectangle::Rectangle(std::vector<double> &data)
{
    x0 = data[0];
    y0 = data[1];
    x1 = data[2];
    y1 = data[3];
    angle = data[4];
}

void Rectangle::setCoord(std::vector<double> &data)
{
    x0 = data[0];
    y0 = data[1];
    x1 = data[2];
    y1 = data[3];
    angle = data[4];
}

std::vector<double> Rectangle::getCoord()
{
    std::vector<double> data;
    data.push_back(x0);
    data.push_back(y0);
    data.push_back(x1);
    data.push_back(y1);
    data.push_back(angle);
    return data;
}

std::pair<double, double> Rectangle::centrePoint()
{
    return std::pair<double, double>((x0 + x1) / 2, (y0 + y1) / 2);
}

void Rectangle::shift(double shiftX, double shiftY)
{
    x0 += shiftX;
    y0 += shiftY;
    x1 += shiftX;
    y1 += shiftY;
}

void Rectangle::rotation(double rotAngle)
{
    angle = rotAngle;
}

void Rectangle::extansion(double extCoef)
{
    if(extCoef != 0)
    {
        std::pair<double, double> centreP = centrePoint();
        x0 = centreP.first + (x0 - centreP.first) * extCoef;
        y0 = centreP.second + (y0 - centreP.second) * extCoef;
        x1 = centreP.first + (x1 - centreP.first) * extCoef;
        y1 = centreP.second + (y1 - centreP.second) * extCoef;
    }
}

typeFigure Rectangle::type()
{
    return rectangle;
}

std::string Rectangle::dataToString()
{
    return "Rectangle " + std::to_string(x0) + " " + std::to_string(y0) + " "
                        + std::to_string(x1) + " " + std::to_string(y1) + " "
                        + std::to_string(angle);
}
